package view.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Observable;

import javax.swing.JComponent;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.MouseInputListener;

public class ComponentObserver extends Observable implements 
	ComponentListener, 
	MouseListener, 
	MouseMotionListener, 
	MouseInputListener, 
	MouseWheelListener,
	ActionListener,
	InputMethodListener,
	KeyListener,
	AncestorListener,
	ContainerListener,
	HierarchyBoundsListener,
	HierarchyListener,
	PropertyChangeListener,
	FocusListener
{
	
	private JComponent watched=null;
	

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		this.notifyAll();
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		this.notifyAll();
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		this.notifyAll();
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		this.notifyAll();
	}

	@Override
	public void mousePressed(MouseEvent e) {
		this.notifyAll();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		this.notifyAll();
	}

	@Override
	public void mouseEntered(MouseEvent e) {
//		this.notifyAll();
	}

	@Override
	public void mouseExited(MouseEvent e) {
//		this.notifyAll();
	}

	@Override
	public void componentResized(ComponentEvent e) {
		this.notifyAll();
	}

	@Override
	public void componentMoved(ComponentEvent e) {
		this.notifyAll();
	}

	@Override
	public void componentShown(ComponentEvent e) {
		this.notifyAll();
	}

	@Override
	public void componentHidden(ComponentEvent e) {
		this.notifyAll();
	}

	public JComponent getWatched() {
		return watched;
	}

	public void setWatched(JComponent watched) {
		if (this.watched!=null) {
			this.watched.removeAncestorListener(this);
			this.watched.removeComponentListener(this);
			this.watched.removeContainerListener(this);
			this.watched.removeFocusListener(this);
			this.watched.removeHierarchyBoundsListener(this);
			this.watched.removeHierarchyListener(this);
			this.watched.removeInputMethodListener(this);
			this.watched.removeKeyListener(this);
			this.watched.removeMouseListener(this);
			this.watched.removeMouseMotionListener(this);
			this.watched.removeMouseWheelListener(this);
			this.watched.removePropertyChangeListener(this);
		}
		this.watched = watched;
		if (this.watched!=null) {
			this.watched.addAncestorListener(this);
			this.watched.addComponentListener(this);
			this.watched.addContainerListener(this);
			this.watched.addFocusListener(this);
			this.watched.addHierarchyBoundsListener(this);
			this.watched.addHierarchyListener(this);
			this.watched.addInputMethodListener(this);
			this.watched.addKeyListener(this);
			this.watched.addMouseListener(this);
			this.watched.addMouseMotionListener(this);
			this.watched.addMouseWheelListener(this);
			this.watched.addPropertyChangeListener(this);
		}
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
//		this.notifyAll();
	}

	@Override
	public void hierarchyChanged(HierarchyEvent e) {
//		this.notifyAll();
	}

	@Override
	public void ancestorMoved(HierarchyEvent e) {
//		this.notifyAll();
	}

	@Override
	public void ancestorResized(HierarchyEvent e) {
//		this.notifyAll();
	}

	@Override
	public void componentAdded(ContainerEvent e) {
//		this.notifyAll();
	}

	@Override
	public void componentRemoved(ContainerEvent e) {
//		this.notifyAll();
	}

	@Override
	public void ancestorAdded(AncestorEvent event) {
//		this.notifyAll();
	}

	@Override
	public void ancestorRemoved(AncestorEvent event) {
//		this.notifyAll();
	}

	@Override
	public void ancestorMoved(AncestorEvent event) {
//		this.notifyAll();
	}

	@Override
	public void keyTyped(KeyEvent e) {
		this.notifyAll();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		this.notifyAll();
	}

	@Override
	public void keyReleased(KeyEvent e) {
		this.notifyAll();
	}

	@Override
	public void inputMethodTextChanged(InputMethodEvent event) {
		this.notifyAll();
	}

	@Override
	public void caretPositionChanged(InputMethodEvent event) {
		this.notifyAll();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.notifyAll();
	}

	@Override
	public void focusGained(FocusEvent e) {
		this.notifyAll();
	}

	@Override
	public void focusLost(FocusEvent e) {
		this.notifyAll();
	}
}
